const fs = require('fs')
const path = require('path')
const http = require('http')

const server = http.createServer()
server.on('request', (req, res) => {
  // res.setHeader('Content-Type', 'text/html;charset=utf-8')
  let url = req.url === '/' ? 'index.html' : req.url
  fs.readFile(path.join(__dirname, '/clock', url), 'utf-8', (err, str) => {
    if (err) {
      res.end('404 not found')
    } else {
      res.end(str)
    }
  })
})
server.listen(8089, () => {
  console.log('服务器启动成功,请访问http://127.0.0.1:8089');
})